<?php
/**
 *      [迷你云] (C)2009-2012 南京恒为网络科技.
 *   软件仅供研究与学习使用，如需商用，请访问www.miniyun.cn获得授权
 * 
 */
?>
<?php

class Controller extends CController
{

	public $layout='//layouts/column1';

	public $menu=array();
 
	public $breadcrumbs=array();
	public function filters()
	{
				$user = Yii::app()->session["user"];
		if(isset($user)){
			$appId=Yii::app()->session["appId"];
			$deviceId=Yii::app()->session["deviceId"];
			$userId = $user["id"];
			$onlineDevice = OnlineDevice::model()->find("user_id=? and application_id=? and device_id=?",array($userId,$appId,$deviceId));
			if(isset($onlineDevice)){
				$onlineDevice->updated_at = new CDbExpression('NOW()');
				$onlineDevice->save();			}else{
				$onlineDevice = new OnlineDevice();
				$onlineDevice->user_id=$userId;
				$onlineDevice->application_id = $appId;
				$onlineDevice->device_id  = $deviceId;
				$onlineDevice->created_at = new CDbExpression('NOW()');
				$onlineDevice->updated_at = new CDbExpression('NOW()');
				$onlineDevice->save();
			}
						$count = OnlineDevice::model()->count("(now()-updated_at)<=300");
						$change = true;
			$option = Option::model()->find("option_name='max_online_users'");
			if(isset($option)){
				$beforeCount = intVal($option["option_value"]);
				if($beforeCount>=$count){
					$change = false;
				}
			}
			if($change){
				if(isset($option)){
					$option["option_value"]=$count;
				}else{
					$option = new Option();
					$option["option_name"] = "max_online_users";
					$option["option_value"] = $count;
				}
				$option->save();
			}
		}
		 
		Yii::app()->setLanguage("zh_cn");
		return array(
		);
	} 
}